<template>
    <div>{{modelValue}}</div>
</template>

<script setup lang='ts'>
import {onMounted, onUnmounted, ref,} from 'vue'

const emit = defineEmits<{
    (e: 'update:modelValue', time: string): void
}>()
defineProps({
    modelValue: String
})

const timer = ref<number|undefined>(undefined)

onMounted(refreshTimeAlways)
onUnmounted(() => clearInterval(timer.value))


function refreshTimeAlways() {
    timer.value = setInterval(() => {
        let time = new Date().toLocaleDateString() + ' ' + new Date().toLocaleTimeString()
        emit('update:modelValue', time)
    }, 1000);
}

function confirm() {
    clearInterval(timer.value)
}


</script>